package com.xzz.mybatis.generator.dcevm.controller;

import com.xzz.mybatis.generator.dcevm.fo.MyDynamicCodeFO;
import com.xzz.mybatis.generator.dcevm.service.MyDynamicCodeHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 动态代码替换controller
 */
@Controller
@RequestMapping("/dcevm")
public class MyDynamicCodeController {

    @Resource
    private MyDynamicCodeHelper dynamicCodeHelper;

    /** 具体的替换页面 */
    @GetMapping(value = {"/indexPage", "/"})
    public ModelAndView indexPage(){
        ModelAndView modelAndView = new ModelAndView("dynamic_code");
        modelAndView.addObject("xAuthToken", "xAuthToken");
        return modelAndView;
    }

    /** 上传文件并发送消息 */
    @PostMapping(value = {"/uploadAndSendBusMsg"})
    @ResponseBody
    public void uploadAndSendBusMsg(MultipartFile file, MyDynamicCodeFO dynamicCodeFO){
        if(file==null|| StringUtils.isBlank(dynamicCodeFO.getFullClassName())){
        }

        dynamicCodeHelper.doUploadAndSendBusMsg(file, dynamicCodeFO);
    }
}
